<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>个人中心</title>
    <link rel="stylesheet" href="/ehome/static/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" name="editForm" id="editForm"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->

    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">id</label>
            <div class="layui-input-block">
                <input type="text" name="id"   autocomplete="off" class="layui-input"
                       lay-verify="required" readonly="readonly">
            </div>
        </div>
        <label class="layui-form-label">选择分店</label>
        <div class="layui-input-block">
            <select name="companId" lay-filter="subCompany">
                <option value="1000" >眉山店</option>
                <option value="1001">双楠店</option>
                <option value="1002">高新店</option>
                <option value="1003">温江店</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户类型</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="type">
                <option value="0">管理员</option>
                <option value="1">录入人员</option>
                <option value="2">客服</option>
                <option value="3">派件员</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工号</label>
        <div class="layui-input-block">
            <input type="text" name="jobNumber"   autocomplete="off" class="layui-input"
                   lay-verify="required" value="KF001" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">初始密码</label>
        <div class="layui-input-block">
            <input type="password" name="password"  autocomplete="off" class="layui-input"  lay-verify="required" value="123">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name"  autocomplete="off" class="layui-input"  lay-verify="required" value="张三丰">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phoneNumber"  autocomplete="off" class="layui-input"
                   lay-verify="required|phone|number" value="13344445678">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">身份证</label>
        <div class="layui-input-block">
            <input type="text" name="idCard" autocomplete="off" class="layui-input"  lay-verify="required|identity"
                   value="510105198454212341">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="addUser">添加用户</button>
        </div>
    </div>

</form>
<script src="/ehome/static/layui.js"></script>
<script src="/ehome/static/lib/jquery-3.1.1.min.js"></script>
<script>
    layui.use('form', function(){
        var form = layui.form;

        //表单异步提交
        form.on('submit(addUser)', function(obj){
           // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
          //  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
     //       console.log(obj.field) //当前容器的全部表单字段，名值对形式：{name: value} json
            $.ajax({
                //自定义请求头设定业务类型
                headers:{type:"addUser"}
                ,type : "post"  //提交方式
                ,url : "/ehome/sysUser.do"//路径
                ,data :{formData:JSON.stringify(obj.field)}
                ,dataType: 'json'
                ,success : function(res) {
                    //返回数据根据结果进行相应的处理
                    console.log(res)
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        layer.msg(res.msg);
                    });

                }
                ,error:function (e){
                    console.log(e);
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

        });
    });
</script>
</body>
</html>